<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="/shop/include :: header"></head>
<body>
	<form class="layui-form" action="" lay-filter="shop_supply_goods_rule-add-form" style="margin-top: 20px;">
		<!--  -->
 		<!--  -->
		<div class="layui-form-item" style="display: none">
			<label class="layui-form-label">供应商ID：</label>
			<div class="layui-input-block">
				<input id="supplyId" name="supplyId" placeholder="请输入供应商ID"
					class="layui-input" lay-verify="required" autocomplete="off" th:value="${supplyId}" readonly>
			</div>
		</div>
 		<!--  -->
		<div class="layui-form-item">
			<label class="layui-form-label">商品编码：</label>
			<div class="layui-input-block">
				<input id="goodsCode" name="goodsCode" placeholder="请输入商品编码"
					class="layui-input" lay-verify="required" autocomplete="off" th:value="${goodsCode}" readonly>
			</div>
		</div>
 		<!--  -->
		<div class="layui-form-item">
			<label class="layui-form-label">商品属性：</label>
			<div class="layui-input-block">
				<select name="goodsWarehouseId" id="goodsWarehouseId" autocomplete="off"
						placeholder="请选择商品属性"
						class="layui-input">
				</select>
			</div>
		</div>
 		<!--  -->
		<div class="layui-form-item">
			<label class="layui-form-label">购买数量：</label>
			<div class="layui-input-block">
				<input id="size" name="size" placeholder="请输入购买数量"
					class="layui-input" lay-verify="required" autocomplete="off">
			</div>
		</div>
 		<!--  -->
		<div class="layui-form-item">
			<label class="layui-form-label">单价：</label>
			<div class="layui-input-block">
				<input id="salePrice" name="salePrice" placeholder="请输入单价"
					class="layui-input" lay-verify="required" autocomplete="off">
			</div>
		</div>
 		<div class="layui-form-item" style="text-align: center">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit="" lay-filter="shop_supply_goods_rule-add">立即提交</button>
			</div>
		</div>
	</form>
	<div th:include="/shop/include::footer"></div>
	<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
	<script>
		layui.use([ 'layer', 'jquery', 'form', 'laydate' ], function() {
			var $ = layui.jquery;
			var laydate = layui.laydate;
			var layer = layui.layer;
			var form = layui.form;

			$.ajax({
				url: '/platform/supplygoodswarehouse/getSupplyGoodsWarehouseByGoodsCode?goodsCode='+$("#goodsCode").val(),
				type: "get",
				success: function (result) {
					if (result.status == "SUCCESS") {
						if (result.data != null) {
							var $html = "";
							$.each(result.data, function (index, item) {
								$html += "<option value='" + item.id + "'>" + item.name + "</option>";
							});
							$("#goodsWarehouseId").append($html);
							form.render('select');
						}
					} else {
						layer.msg(result.message)
					}
				},
				error: function (result) {
					layer.msg("查询商品属性失败")
				}
			});

  			//监听提交
			form.on('submit(shop_supply_goods_rule-add)', function(data) {
				$.ajax({
					url: '/platform/supplygoodsrule/add',
					type: "post",
					data: JSON.stringify(data.field),
					contentType: 'application/json; charset=utf-8', // 很重要
					async: false,
					success: function (result) {
						if (result.status == "SUCCESS") {
							layer.msg(result.message, {
								offset: '15px'
								, icon: 1
								, time: 1000
							}, function () {
								window.parent.location.reload();
							});
						} else {
							layer.msg(result.message)
						}
					}
				});
				return false;
			});
		});
	</script>
</body>
</html>